package com.heima.admin.job;

import com.heima.admin.feign.WemediaFeign;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Log4j2
public class WeMediaNewsAutoScanJob {

    @Autowired
    private WemediaNewsAutoScanService weMediaNewsAutoScanService;

    @Autowired
    private WemediaFeign wemediaFeign;

    /**
     * 执行定时任务
     *
     * @param param 固定参数 不可变
     * @return 固定条件不可变 固定响应
     * @throws Exception
     */
    @XxlJob("wemediaAutoScanJob")  //JobHandler 必须和界面中的该值一致
    public ReturnT<String> hello(String param) throws Exception {
        //获取审核通过并到时的文章
        List<Integer> releaseIdList = wemediaFeign.findRelease();

        //遍历文章获取id
        if (null != releaseIdList && releaseIdList.size() > 0) {
            for (Integer id : releaseIdList) {

                //调用审核方法
                weMediaNewsAutoScanService.autoScanByMediaNewsId(id);
            }
        }
        return ReturnT.SUCCESS;
    }

}